<?
set_time_limit(0);

include_once ("../config.php");

// 파일이 존재한다면 설치할 수 없다.
if (file_exists("../dbconfig.php")) {
    echo "<meta http-equiv='content-type' content='text/html; charset=$g4[charset]'>";
    echo <<<HEREDOC
    <script language="JavaScript">
    alert("설치하실 수 없습니다.");
    location.href="../";
    </script>
HEREDOC;
    exit;
}

$gmnow = gmdate("D, d M Y H:i:s") . " GMT";
header("Expires: 0"); // rfc2616 - Section 14.21
header("Last-Modified: " . $gmnow);
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: pre-check=0, post-check=0, max-age=0"); // HTTP/1.1
header("Pragma: no-cache"); // HTTP/1.0

$cubrid_host  = $_POST[cubrid_host];
$cubrid_port  = $_POST[cubrid_port];
$cubrid_user  = $_POST[cubrid_user];
$cubrid_pass  = $_POST[cubrid_pass];
$cubrid_db    = $_POST[cubrid_db];
$admin_id    = $_POST[admin_id];
$admin_pass  = $_POST[admin_pass];
$admin_name  = $_POST[admin_name];
$admin_email = $_POST[admin_email];

$dblink = @cubrid_connect($cubrid_host, $cubrid_port, $cubrid_db, $cubrid_user, $cubrid_pass);
if (!$dblink) {
    echo "<meta http-equiv='content-type' content='text/html; charset=$g4[charset]'>";
    echo "<script language='JavaScript'>alert('CUBRID Host, Port, User, Password, DB를 확인해 주십시오.');history.back();</script>"; 
    exit;
}

?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=<?=$g4[charset]?>">
<title>그누보드4 설치 (3/3) - DB</title>
<style type="text/css">
<!--
.body {
	font-size: 12px;
}
.box {
	background-color: #FCFCFC;
    color:#18307B;
	font-size: 12px;
}
.nobox {
	background-color: #FCFCFC;
    border-style:none;
    font-size: 12px;
}
-->
</style>
</head>

<body background="img/all_bg.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div align="center">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <table width="587" border="0" cellspacing="0" cellpadding="0">
    <form name=frminstall2>
    <tr> 
                <td colspan="3"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="587" height="22">
                        <param name="movie" value="img/top.swf">
                        <param name="quality" value="high">
                        <embed src="img/top.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="587" height="22"></embed></object></td>
    </tr>
    <tr> 
      <td width="3"><img src="img/box_left.gif" width="3" height="340"></td>
      <td width="581" valign="top" bgcolor="#FCFCFC"><table width="581" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td><img src="img/box_title.gif" width="581" height="56"></td>
          </tr>
        </table>
        <br>
        <table width="541" border="0" align="center" cellpadding="0" cellspacing="0" class="body">
          <tr> 
            <td>설치를 시작합니다. <font color="#CC0000">설치중 작업을 중단하지 마십시오. </font></td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td><div align="left">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input name="status_bar" type="text" class="box" size="76" readonly></div></td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td><table width="350" border="0" align="center" cellpadding="5" cellspacing="0" class="body">
                <tr> 
                  <td width="50"> </td>
                  <td width="300"><input type=text name=job1 class=nobox size=80 readonly></td>
                </tr>
                <tr> 
                  <td width="50"> </td>
                  <td width="300"><input type=text name=job2 class=nobox size=80 readonly></td>
                </tr>
                <tr> 
                  <td width="50"> </td>
                  <td width="300"><input type=text name=job3 class=nobox size=80 readonly></td>
                </tr>
                <tr> 
                  <td width="50"> 
                    <div align="center"></div></td>
                  <td width="300"><input type=text name=job4 class=nobox size=80 readonly></td>
                </tr>
              </table></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td><input type=text name=job5 class=nobox size=90 readonly></td>
          </tr>
        </table>
        <table width="562" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height=20><img src="img/box_line.gif" width="562" height="2"></td>
          </tr>
        </table>
        <table width="551" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr> 
            <td align="right"> 
              <input type="button" name="btn_next" disabled value="메인화면" onclick="location.href='../';">
            </td>
          </tr>
        </table></td>
      <td width="3"><img src="img/box_right.gif" width="3" height="340"></td>
    </tr>
    <tr> 
      <td colspan="3"><img src="img/box_bottom.gif" width="587" height="3"></td>
    </tr>
    </form>
  </table>
</div>
<?
flush(); usleep(50000); 


// 테이블 생성 ------------------------------------
$file = implode("", file("./sql_gnuboard4.sql"));
eval("\$file = \"$file\";");
$f = explode(";", $file);
for ($i=0; $i<count($f); $i++) {
    if (trim($f[$i]) == "") continue;
	cubrid_execute($dblink, $f[$i]) or die(cubrid_error_msg());
}
// 테이블 생성 end ------------------------------------

echo "<script>document.frminstall2.job1.value='전체 테이블 생성중';</script>";
flush(); usleep(50000); 


for ($i=0; $i<45; $i++)
{
    echo "<script language='JavaScript'>document.frminstall2.status_bar.value += '■';</script>\n";
    flush();
    usleep(500); 
}

echo "<script>document.frminstall2.job1.value='전체 테이블 생성 완료';</script>";
flush(); usleep(50000); 

$read_point = -1;
$write_point = 5;
$comment_point = 1;
$download_point = -20;

//-------------------------------------------------------------------------------------------------
// config 테이블 설정
$sql = " insert into $g4[config_table]
            (cf_title,
			 cf_admin,
			 cf_use_point,
			 cf_use_norobot,
			 cf_use_copy_log,
			cf_login_point,
			cf_memo_send_point,
			cf_cut_name,
			cf_nick_modify,
			cf_new_skin,
			cf_new_rows,
			cf_search_skin,
			cf_connect_skin,
			cf_read_point,
			cf_write_point,
			cf_comment_point,
			cf_download_point,
			cf_search_bgcolor,
			cf_search_color,
			cf_write_pages,
			cf_link_target,
			cf_delay_sec,
			cf_filter,
			cf_possible_ip,
			cf_intercept_ip,
			cf_member_skin,
			cf_register_level,
			cf_register_point,
			cf_icon_level,
			cf_leave_day,
			cf_search_part,
			cf_email_use,
			cf_prohibit_id,
			cf_prohibit_email,
			cf_new_del,
			cf_memo_del,
			cf_visit_del,
			cf_popular_del,
			cf_use_member_icon,
			cf_member_icon_size,
			cf_member_icon_width,
			cf_member_icon_height,
			cf_login_minutes,
			cf_image_extension,
			cf_flash_extension,
			cf_movie_extension,
			cf_formmail_is_member,
			cf_page_rows,
			cf_stipulation,
			cf_privacy)
		values(
			'그누보드4',
			'$admin_id',
            1,
			1,
            1,
            100,
            500,
            10,
            60,
            'basic',
            15,
            'basic',
            'basic',
            $read_point,
            $write_point,
            $comment_point,
            $download_point,
            'YELLOW',
            'RED',
            10,
            '_blank',
            30,
            '18아,18놈,18새끼,18년,18뇬,18노,18것,18넘,개년,개놈,개뇬,개새,개색끼,개세끼,개세이,개쉐이,개쉑,개쉽,개시키,개자식,개좆,게색기,게색끼,광뇬,뇬,눈깔,뉘미럴,니귀미,니기미,니미,도촬,되질래,뒈져라,뒈진다,디져라,디진다,디질래,병쉰,병신,뻐큐,뻑큐,뽁큐,삐리넷,새꺄,쉬발,쉬밸,쉬팔,쉽알,스패킹,스팽,시벌,시부랄,시부럴,시부리,시불,시브랄,시팍,시팔,시펄,실밸,십8,십쌔,십창,싶알,쌉년,썅놈,쌔끼,쌩쑈,썅,써벌,썩을년,쎄꺄,쎄엑,쓰바,쓰발,쓰벌,쓰팔,씨8,씨댕,씨바,씨발,씨뱅,씨봉알,씨부랄,씨부럴,씨부렁,씨부리,씨불,씨브랄,씨빠,씨빨,씨뽀랄,씨팍,씨팔,씨펄,씹,아가리,아갈이,엄창,접년,잡놈,재랄,저주글,조까,조빠,조쟁이,조지냐,조진다,조질래,존나,존니,좀물,좁년,좃,좆,좇,쥐랄,쥐롤,쥬디,지랄,지럴,지롤,지미랄,쫍빱,凸,퍽큐,뻑큐,빠큐,ㅅㅂㄹㅁ',
            '',
            '',
            'basic',
            2,
            1000,
            2,
            30,
            10000,
            1,
            'admin,administrator,관리자,운영자,어드민,주인장,webmaster,웹마스터,sysop,시삽,시샵,manager,매니저,메니저,root,루트,su,guest,방문객',
            'hanmail.net\\ndaum.net',
            30,
            180,
            180,
            180,
            2,
            5000,
            22,
            22,
            10,
            'gif|jpg|jpeg|png',
            'swf',
            'asx|asf|wmv|wma|mpg|mpeg|mov|avi|mp3',
            1,
            15,
            '해당 홈페이지에 맞는 회원가입약관을 입력합니다.',
            '해당 홈페이지에 맞는 개인정보취급방침을 입력합니다.')";

cubrid_execute($dblink, $sql) or die(cubrid_error_msg() . "<p>" . $sql);

// 운영자 회원가입
$sql = " insert into $g4[member_table]
            ( mb_id,
			mb_password,
			mb_name,
			mb_nick,
			mb_email,
			mb_jumin,
			mb_level,
			mb_mailling,
			mb_open,
			mb_email_certify,
			mb_datetime,
			mb_ip)
		values(
			'$admin_id',
             '".md5($admin_pass)."',
            '$admin_name',
            '$admin_name',
            '$admin_email',
            '".md5("1111111111118")."',
            10,
            1,
            1,
            '$g4[time_ymdhis]',
            '$g4[time_ymdhis]',
            '$_SERVER[REMOTE_ADDR]')";

cubrid_execute($dblink, $sql) or die(cubrid_error_msg() . "<p>" . $sql);
cubrid_commit($dblink);

echo "<script>document.frminstall2.job2.value='DB설정 완료';</script>";
flush(); usleep(50000); 
//-------------------------------------------------------------------------------------------------

// DB 설정 파일 생성
$file = "../dbconfig.php";
$f = @fopen($file, "w");

fwrite($f, "<?\n");
fwrite($f, "\$cubrid_host = '$cubrid_host';\n");
fwrite($f, "\$cubrid_port = '$cubrid_port';\n");
fwrite($f, "\$cubrid_user = '$cubrid_user';\n");
fwrite($f, "\$cubrid_password = '$cubrid_pass';\n");
fwrite($f, "\$cubrid_db = '$cubrid_db';\n");
fwrite($f, "?>");

fclose($f);
@chmod($file, 0606);
echo "<script>document.frminstall2.job3.value='DB설정 파일 생성 완료';</script>";


flush(); usleep(50000); 


// 1.00.09 - data/log 삽입
// 디렉토리 생성
$dir_arr = array ("../extend",
                  "../data",
                  "../data/file",
                  "../data/log",
                  "../data/member",
                  "../data/session",
                  "../data/$g4[editor]");
for ($i=0; $i<count($dir_arr); $i++) 
{
    @mkdir($dir_arr[$i], 0707);
    @chmod($dir_arr[$i], 0707);

    // 디렉토리에 있는 파일의 목록을 보이지 않게 한다.
    $file = $dir_arr[$i] . "/index.php";
    $f = @fopen($file, "w");
    @fwrite($f, "");
    @fclose($f);
    @chmod($file, 0606);
}

@rename("../install", "../install.bak");
//-------------------------------------------------------------------------------------------------

echo "<script language='JavaScript'>document.frminstall2.status_bar.value += '■';</script>\n";
flush();
sleep(1);

echo "<script>document.frminstall2.job4.value='필요한 Table, File, 디렉토리 생성을 모두 완료 하였습니다.';</script>";
echo "<script>document.frminstall2.job5.value='* 메인화면에서 운영자 로그인을 한 후 운영자 화면으로 이동하여 환경설정을 변경해 주십시오.';</script>";
flush(); usleep(50000); 
?>

<script>document.frminstall2.btn_next.disabled = false;</script>
<script>document.frminstall2.btn_next.focus();</script>

</body>
</html>